<style lang="less" scoped>
</style>
<template>
    <div>
        <base-model
            @model-close="staffClose"
            @model-ok="staffOk"
            title="添加员工"
            :value="value"
            :loading="loading"
            @input="updateshow">
            <Form :model="addStaffForm" :label-width="120" ref="addStaffForm" :rules="rule">
                <FormItem label="工号：" prop="nub">
                    <Input v-model="addStaffForm.nub" placeholder="请输入工号" :maxlength="16" style="width: 200px"></Input>
                </FormItem>
                <FormItem label="员工姓名：" prop="realname">
                    <Input v-model="addStaffForm.realname" placeholder="请输入员工姓名" :maxlength="16" style="width: 200px"></Input>
                </FormItem>
                <FormItem label="联系方式：" prop="phone">
                    <Input v-model="addStaffForm.phone" placeholder="请输入员工联系方式" :maxlength="16" style="width: 200px"></Input>
                </FormItem>
                <FormItem label="邮箱：" prop="email">
                    <Input v-model="addStaffForm.email" placeholder="请输入员工邮箱" :maxlength="16" style="width: 200px"></Input>
                </FormItem>
                <FormItem label="岗位：" prop="post">
                    <Input v-model="addStaffForm.post" placeholder="请输入员工岗位" :maxlength="16" style="width: 200px"></Input>
                </FormItem>
                <FormItem label="备注：" prop="remark">
                    <Input v-model="addStaffForm.remark" placeholder="请输入备注信息" type="textarea" :maxlength="80" style="width: 80%"></Input>
                </FormItem>
                <FormItem label="是否创建帐号：" prop="userdisable">
                    <i-switch v-model="userdisable" size="large">
                        <span slot="open">是</span>
                        <span slot="close">否</span>
                    </i-switch>
                </FormItem>
                <FormItem v-if="userdisable" label="用户名：" prop="name">
                    <Input v-model="addStaffForm.name" placeholder="请输入用户名" :maxlength="16" style="width: 200px"></Input>
                </FormItem>
                <FormItem v-if="userdisable" label="密码：" prop="password">
                    <Input v-model="addStaffForm.password" placeholder="请输入密码" :maxlength="16" style="width: 200px"></Input>
                </FormItem>
            </Form>
        </base-model>
        <!--<add-user v-model="addUser" :id="userid"></add-user>-->
    </div>
</template>
<script>
    export default {
        name: 'addstaff',
        props: {
            value: {
                type: Boolean,
                default: false
            }
        },
        data () {
            return {
                userid: '',
                addUser: false,
                userdisable: false,
                addStaffForm: {
                    nub: '',
                    realname: '',
                    phone: '',
                    email: '',
                    post: '',
                    name: '',
                    password: '',
                    hours: '',
                    remark: '',
                    state: 1
                },
                loading: true,
                rule: {
                    realname: this.rule.noNull('员工姓名不能为空')
                }
            }
        },
        computed: {
        },
        methods: {
            updateshow (show) {
                this.$emit('input', show)
            },
            reset () {
                this.$refs['addStaffForm'].resetFields();
                for (let item in this.addStaffForm) {
                    this.$set(this.addStaffForm, item, '')
                }
            },
            staffClose () {
                this.reset()
            },
            setuserdata (data) {
                this.$emit('setuserdata', data)
            },
            setmodel (state) {
                this.$emit('setmodel', state)
            },
            staffOk () {
                this.$refs['addStaffForm'].validate((valid) => {
                    if (valid) {
                        this.http.addUser(this, this.addStaffForm, 'addStaffForm')
                    } else {
                        this.loading = false
                        setTimeout(() => {
                            this.loading = true
                        }, 300)
                    }
                })
            }
        },
        components: {
        },
        mounted: function () {
        }
    };
</script>
